package com.sky.controller.user;

import com.sky.controller.BaseController;
import com.sky.dto.ShoppingCatDTO;
import com.sky.entity.ShoppingCatEntity;
import com.sky.result.Result;
import com.sky.result.TableDataInfo;
import com.sky.service.ShoppingCatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCat")
@Api(tags = "C端购物车接口")
@Slf4j
public class ShoppingCatController extends BaseController {

    @Autowired
    private ShoppingCatService shoppingCatService;

    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result add(@RequestBody ShoppingCatDTO catDTO) {
        log.info("添加购物车信息=>{}", catDTO);

        shoppingCatService.add(catDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result list() {
        List<ShoppingCatEntity> list = shoppingCatService.list();

        return Result.success(list);
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result clean() {
        shoppingCatService.clean();
        return Result.success();
    }

    @PostMapping("/sub")
    @ApiOperation("删除购物车的商品")
    public Result sub(@RequestBody ShoppingCatDTO catDTO) {
        shoppingCatService.sub(catDTO);
        return Result.success();
    }

}
